package com.dyava.commons.lock;

import java.io.Closeable;
import java.io.IOException;

/**
 * Created by jjliu on 2020/4/15.
 */
public interface KeyLock extends AutoCloseable {
    /**
     * 默认抢锁等待时间
     */
    public static final int DEFAULT_MAX_WAIT_TIME = 10000;

    /**
     * 尝试加锁
     * @return
     */
    public boolean tryLock();

    /**
     * 阻塞等待锁，长期等不到，会抛异常
     * @param maxWaitTime
     */
    public void lock(int maxWaitTime);

    /**
     * 为了自动化释放
     * @throws Exception
     */
    @Override
    public void close();

}
